<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<title><s:property value="ev_title" /></title>
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link href="${aier_css_url}jq/jq.css" rel="Stylesheet" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}/ui.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}comm/text.css" />
<link rel="stylesheet" href="${aier_css_url}admin/admin.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/1.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/arrayList.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}comm/text.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
    $("#schoolinfo").jqGrid({                
        url:'${aier_url}${aier_urijs}info_searchSchool${aier_suffix}',                
        datatype:"json",                
        mtype:'GET',
        height:'230',
        width:'960',              
        colNames:['学校名称','用户类型','剩余短信条数','购买短信','查看购买记录','sid'],                
        colModel:[                    
        {name:'name',index:'name',width:120,align:'center'},
        {name:'methodStr',index:'methodStr',width:120,align:'center'},
        {name:'mesCount',index:'mesCount',width:100,align:'center'},
        {name:'revoked1',index:'revoked1',width:120,align:'center'},
        {name:'revoked2',index:'revoked2',width:120,align:'center'},
        {name:'sid',index:'sid',hidden : true}
        ],
        //autowidth:true,
        jsonReader: {
            root:"schoolList",
            page: "page",
            total: "page_count",
            records : "count",
            repeatitems: false
        },
        pager: jQuery("#schoolpage"),
        prmNames : {page:"page",sort: "sort"},
        rowNum: 10,
        sortname: 'sid',
        hidegrid: false,
        sortorder: 'asc',
        viewrecords: true,
        caption: '购买短信',
        gridComplete:function(){
            var ids=jQuery("#schoolinfo").jqGrid('getDataIDs');
            for(var i=0; i<ids.length; i++){
                var id=ids[i]; 
                var re1 = "<a href='javascript:;' class='jqtrow' onclick='buyService(" + id + ")'>购买短信</a>";
                var re2 = "<a href='javascript:;' class='jqtrow' onclick='buyList(" + id + ")'>查看购买记录</a>";
                jQuery("#schoolinfo").jqGrid('setRowData', ids[i], { revoked1: re1,revoked2: re2});
            }
        }
    }).navGrid("#schoolpage", { edit: false, add: false, del: false, search: false });
}); 
</script>
<body style="background-color: #EEF2FB;">
    
    <div style="background-color: #EEF2FB;width: 100%;height: 700px; ">
       
         <div id="tabs">
             <ul>
                 <li><a href="#tabs-1">购买短信</a></li>
             </ul>
             <div id="tabs-1" style="height: 500px;">
                 <div class="d_content">
                    <div class="d_scnOut">
                        <div class="d_scname">
                            <label for="name">学校地址:</label>
                        </div>
                        <div class="sel_region">
                            <s:action name="cityutil" namespace="/common"
                                executeResult="true">
                                <s:param name="cityid">-1</s:param>
                            </s:action>
                        </div>
                    </div>
                    <div class="d_scnOut">
                        <div class="d_scname" style="margin-left: 0px;">
                            <label for="name">名称: </label>
                        </div>
                        <div class="d_sctext">
                            <input type="text" id="sname" />
                        </div>
                    </div>
                    <div class="d_scnOut" style="margin-left: 300px;margin-top: -40px;">
                        <div class="d_scname" >
                            <label for="name">用户类型: </label>
                        </div>
                        <div class="sel_region">
                        <select id="method">
                            <option value="-1">不限</option>
                            <option value="2">购买短信用户</option>
                            <option value="1">月付费用户</option>
                        </select>
                    </div>
                        
                    </div>
                    <div style="margin-left: 600px;margin-top: -47px;">
                        <button onclick="search();"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                            role="button" aria-disabled="false">
                            <span class="ui-button-text">查询</span>
                        </button>
                    </div>
                    
                     <!-- 表格 -->
                     <div style="margin-left: 0px;margin-top: 0px;">
                         <table id="schoolinfo"></table>
                         <div id="schoolpage"></div>
                     </div>
                            
				</div>
				
				<!-- 弹出层内容 充值-->
                <div id="buy_service" title="购买" style="display: none;">
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>学校名称:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <span id="name" class="txt_scname"></span>
                        </div>
                    </div>
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>短信单价:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <input id="price" value="0.07"><label> 元</label>
                        </div>
                    </div>
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>短信条数:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <input id="count"><label> 条</label>
                        </div>
                    </div>
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>总价:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <input id="total"><label> 元</label>
                        </div>
                    </div>
                            
                    <button style="margin-top: 30px;margin-left: 200px" onclick="buy();"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                            role="button" aria-disabled="false">
                            <span class="ui-button-text">购买</span>
                    </button>
                </div>
                
			</div>
        </div>
	</div>

	<script type="text/javascript">
		$("#tabs").tabs();
		var sid;
		// 弹出层
	    $(function() {
	        $("#buy_service").dialog({
	            //背景变暗
	            modal: true,
	            autoOpen : false,
	            show : "blind",
	            width : "500",
	            height : "400"
	        });
	    
	    });
	
	  // 根据条件查询学校列表 
      function search(){
         var pcid = -1;
         if(acity.cid>-1){
            pcid = acity.cid;
         }
         jQuery("#schoolinfo").jqGrid('setGridParam',{url:'${aier_url}${aier_urijs}info_searchSchool${aier_suffix}'+"?cid="+pcid+"&sname="+$("#sname").val()+"&method="+$("#method").val(),page:1}).trigger("reloadGrid");
     }
     // 弹出充值对话框
     function buyService(id) {
         sid = jQuery("#schoolinfo").jqGrid('getRowData', id).sid;
         $("#name").html(jQuery("#schoolinfo").jqGrid('getRowData', id).name);
         $("#buy_service").dialog("open");
     }
     // 充值
     function buy() {
    	 var price = $("#price").val();
    	 if (!isNum(price)) {
             $().message("请输入有效的短信单价!");
             return;
         }
    	 var count = $("#count").val();
         if (!isNum1(count)) {
             $().message("请输入有效的短信条数!");
             return;
         }
         var total = $("#total").val();
         if (!isNum(total)) {
             $().message("请输入有效的短信总价!");
             return;
         }
         var fun = function(data) {
             if(1==data.s){
                 $("#month").val("");
                 $("#day").val("");
                 $('#r_month').attr("checked","checked");
                 $().message("充值成功!");
                 $("#schoolinfo").trigger("reloadGrid");
                 $("#buy_service").dialog("close");
                 $("#count").val("");
                 $("#total").val("");
             }else{
                 $().message("充值失败,请稍后再试!");
             }
         };
         exeAjax(ajaxUrl("${aier_url}${aier_urijs}info_buyMessage${aier_suffix}"), fun, 
         {
             "sid" :sid,
             "price":price,
             "mcount":count,
             "total":total
         });
    	 
     }
     
     // 查询购买记录
     function buyList(id) {
         window.location.href = "${aier_url}${aier_uri}info_detail${aier_suffix}?sid="+jQuery("#schoolinfo").jqGrid('getRowData', id).sid;
     }
     
	</script>
</body>
</html>